type Details = {
  art_id: string
  attitude: number
  aut_id: string
  aut_name: string
  aut_photo: string
  comm_count: number
  content: string
  is_collected: boolean
  is_followed: boolean
  like_count: number
  pubdate: string
  read_count: number
  title: string
}
type ArticleType = {
  details: Details
  comments: CommentsType
}
export type Comment = {
  aut_id: string
  aut_name: string
  aut_photo: string
  com_id: string
  content: string
  is_followed: boolean
  is_liking: boolean
  like_count: number
  pubdate: string
  reply_count: number
}
type CommentsType = {
  end_id: string
  last_id: string
  total_count: number
  results: Comment[]
}
const initValue: ArticleType = {
  // 存放文章详情信息
  details: {},
  comments: {},
} as ArticleType
export type ArticleAction =
  | {
      type: 'article/saveArticleDetails'
      payload: Details
    }
  | {
      type: 'article/saveComment'
      payload: CommentsType
    }
export default function reducer(state = initValue, action: ArticleAction) {
  if (action.type === 'article/saveArticleDetails') {
    return {
      ...state,
      details: action.payload,
    }
  }
  if (action.type === 'article/saveComment') {
    return {
      ...state,
      comments: action.payload,
    }
  }
  return state
}
